package com.studentsystem.controller;

import com.studentsystem.common.Result;
import com.studentsystem.dataobject.StudentDO;
import com.studentsystem.dataobject.TeacherDO;
import com.studentsystem.service.TeacherService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (Teacher)表控制层
 */
@RestController
@RequestMapping("teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    @RequiresRoles("teacher")
    @GetMapping("/authorization")
    public Result<Object> authorization() {
        return Result.success(null);
    }

    @GetMapping("/getInfo")
    public Result<TeacherDO> getTeacherInfo(@RequestParam("username") String username) {
        if (StringUtils.isEmpty(username)) {
            return Result.fail("用户名为空", null);
        }

        TeacherDO teacherDO = teacherService.queryByUsername(username);
        if (teacherDO == null) {
            return Result.fail("学生信息为空", null);
        }

        return Result.success(teacherDO);
    }
}